<!DOCTYPE html>
<html>
<body>
<div id="description"></div>
<div id="console"></div>
<script src="../../../resources/js-test.js"></script>
<script src="../../../../../blink/perf_tests/resources/runner.js"></script>
<script type="text/javascript">

description("This test verifies PerfTestRunner.runPerSecond() calls runFunction as many times as expected.");

// Suppress JavaScript trace event console messages.
console.time = function() {};
console.timeEnd = function() {};

var iteration = 0;
var currentTime = 100;
var callsInIterations = [];
var timesInIterations = [0, 10, 30, 60, 200, 200, 200, 200, 750];
var logLines = [];

PerfTestRunner.now = function () {
    iteration++;
    if (iteration % 2 == 0)
        currentTime += timesInIterations.shift();
    return currentTime;
}

PerfTestRunner.log = function (line) { logLines.push(line); }

var originalTimesInIterations = timesInIterations.slice();

PerfTestRunner.measureRunsPerSecond({
    run: function () {
        var i = Math.floor(iteration / 2);
        if (callsInIterations[i] == undefined)
            callsInIterations[i] = 0;
        callsInIterations[i]++;
    },
    iterationCount: 1,
    done: function () {
        debug("Returning times: [" + originalTimesInIterations.join(", ") + "]");
        shouldEvaluateTo("callsInIterations[0]", 1);
        shouldEvaluateTo("callsInIterations[1]", 10);
        shouldBeTrue("callsInIterations[1] + 5 < callsInIterations[2]");
        shouldBeTrue("callsInIterations[2] + 10 < callsInIterations[3]");
        shouldBe("callsInIterations[3]", "callsInIterations[4]");
        shouldBe("callsInIterations[4]", "callsInIterations[5]");
        shouldBe("callsInIterations[5]", "callsInIterations[6]");
        shouldBe("callsInIterations[6]", "callsInIterations[7]");
        shouldBe("callsInIterations[7]", "callsInIterations[8]");
        shouldBeUndefined("callsInIterations[9]");
    }});

var jsTestIsAsync = true;

</script>
</body>
</html>
